home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.metal;
-
- import com.sun.java.swing.JButton;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.UIResource;
- import com.sun.java.swing.plaf.basic.BasicScrollBarUI;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Rectangle;
-
- public class MetalScrollBarUI extends BasicScrollBarUI {
- private static Color shadowColor;
- private static Color highlightColor;
- private static Color thumbColor;
- private static Color thumbShadow;
- private static Color thumbHighlightColor;
- protected MetalBumps bumps;
- protected MetalScrollButton increaseButton;
- protected MetalScrollButton decreaseButton;
- protected static int scrollBarWidth;
- protected ScrollBarListener scrollBarListener = new ScrollBarListener(this);
- public static final String FREE_STANDING_PROP = "JScrollBar.isFreeStanding";
- protected boolean isFreeStanding = true;
-
- protected void configureScrollBarColors() {
- shadowColor = UIManager.getColor("ScrollBar.shadow");
- highlightColor = UIManager.getColor("ScrollBar.highlight");
- thumbColor = UIManager.getColor("ScrollBar.thumb");
- thumbShadow = UIManager.getColor("ScrollBar.thumbShadow");
- thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");
- }
-
- protected JButton createDecreaseButton(int orientation) {
- this.decreaseButton = new MetalScrollButton(orientation, scrollBarWidth, this.isFreeStanding);
- return this.decreaseButton;
- }
-
- protected JButton createIncreaseButton(int orientation) {
- this.increaseButton = new MetalScrollButton(orientation, scrollBarWidth, this.isFreeStanding);
- return this.increaseButton;
- }
-
- public static ComponentUI createUI(JComponent c) {
- return new MetalScrollBarUI();
- }
-
- protected Dimension getMinimumThumbSize() {
- return new Dimension(scrollBarWidth, scrollBarWidth);
- }
-
- public Dimension getPreferredSize(JComponent c) {
- return super.scrollbar.getOrientation() == 1 ? new Dimension(scrollBarWidth, scrollBarWidth * 3 + 10) : new Dimension(scrollBarWidth * 3 + 10, scrollBarWidth);
- }
-
- public void installUI(JComponent c) {
- scrollBarWidth = (Integer)UIManager.get("ScrollBar.width");
- if (((Component)c).getBackground() == null || ((Component)c).getBackground() instanceof UIResource) {
- ((Component)c).setBackground(UIManager.getColor("ScrollBar.background"));
- }
-
- super.installUI(c);
- this.bumps = new MetalBumps(10, 10, thumbHighlightColor, thumbShadow, thumbColor);
- c.addPropertyChangeListener(this.scrollBarListener);
- this.scrollBarListener.handlePropertyChange(c.getClientProperty("JScrollBar.isFreeStanding"));
- }
-
- protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
- if (((Component)c).isEnabled()) {
- g.translate(thumbBounds.x, thumbBounds.y);
- if (super.scrollbar.getOrientation() == 1) {
- if (!this.isFreeStanding) {
- thumbBounds.width += 2;
- }
-
- g.setColor(thumbColor);
- g.fillRect(0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
- g.setColor(thumbShadow);
- g.drawRect(0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
- g.setColor(thumbHighlightColor);
- g.drawLine(1, 1, thumbBounds.width - 3, 1);
- g.drawLine(1, 1, 1, thumbBounds.height - 2);
- this.bumps.setBumpArea(thumbBounds.width - 6, thumbBounds.height - 7);
- this.bumps.paintIcon(c, g, 3, 4);
- if (!this.isFreeStanding) {
- thumbBounds.width -= 2;
- }
- } else {
- if (!this.isFreeStanding) {
- thumbBounds.height += 2;
- }
-
- g.setColor(thumbColor);
- g.fillRect(0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
- g.setColor(thumbShadow);
- g.drawRect(0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
- g.setColor(thumbHighlightColor);
- g.drawLine(1, 1, thumbBounds.width - 3, 1);
- g.drawLine(1, 1, 1, thumbBounds.height - 3);
- this.bumps.setBumpArea(thumbBounds.width - 7, thumbBounds.height - 6);
- this.bumps.paintIcon(c, g, 4, 3);
- if (!this.isFreeStanding) {
- thumbBounds.height -= 2;
- }
- }
-
- g.translate(-thumbBounds.x, -thumbBounds.y);
- }
- }
-
- protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
- g.translate(trackBounds.x, trackBounds.y);
- if (super.scrollbar.getOrientation() == 1) {
- if (!this.isFreeStanding) {
- trackBounds.width += 2;
- }
-
- if (((Component)c).isEnabled()) {
- g.setColor(shadowColor);
- g.drawLine(0, 0, 0, trackBounds.height - 1);
- g.drawLine(trackBounds.width - 2, 0, trackBounds.width - 2, trackBounds.height - 1);
- g.drawLine(2, trackBounds.height - 1, trackBounds.width - 1, trackBounds.height - 1);
- g.drawLine(2, 0, trackBounds.width - 2, 0);
- g.setColor(highlightColor);
- g.drawLine(1, 1, 1, trackBounds.height - 2);
- g.drawLine(1, 1, trackBounds.width - 3, 1);
- g.drawLine(trackBounds.width - 1, 0, trackBounds.width - 1, trackBounds.height - 1);
- } else {
- MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height);
- }
-
- if (!this.isFreeStanding) {
- trackBounds.width -= 2;
- }
- } else {
- if (!this.isFreeStanding) {
- trackBounds.height += 2;
- }
-
- if (((Component)c).isEnabled()) {
- g.setColor(shadowColor);
- g.drawLine(0, 0, trackBounds.width - 1, 0);
- g.drawLine(0, 2, 0, trackBounds.height - 2);
- g.drawLine(0, trackBounds.height - 2, trackBounds.width - 1, trackBounds.height - 2);
- g.drawLine(trackBounds.width - 1, 2, trackBounds.width - 1, trackBounds.height - 1);
- g.setColor(highlightColor);
- g.drawLine(1, 1, trackBounds.width - 2, 1);
- g.drawLine(1, 1, 1, trackBounds.height - 3);
- g.drawLine(0, trackBounds.height - 1, trackBounds.width - 1, trackBounds.height - 1);
- } else {
- MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height);
- }
-
- if (!this.isFreeStanding) {
- trackBounds.height -= 2;
- }
- }
-
- g.translate(-trackBounds.x, -trackBounds.y);
- }
-
- public void uninstallUI(JComponent c) {
- super.uninstallUI(c);
- c.removePropertyChangeListener(this.scrollBarListener);
- }
- }
-